var mobId, mob, stats, modified, MaxRandom, setupTask, ostats, victor, luck;
var 清怪 = true;
var 刷新地图 = false;
var 复活次数 = 11;
var 副本名称 = "觉醒希拉[普通]";
var BOSS_1_id = 8880410;
var BOSS_1_血量倍率 = 1;
var 副本时限 = 1000 * 60 * 50;
var 实例地图 = [450010400, 450010500];
var 准备地图 = 450011990;
var 退场倒计时 = 180;
var 黑魔法师之怒 = 500000;
var 奥尔卡的思念 = 350000;
var 希纳斯之吻 = 3000;
var 路西德的噩梦 = 800;
var dropItems = new Array(new Array(BOSS_1_id, 2614034, 300, 1, 1), new Array(BOSS_1_id, 5062002, 300, 1, 1), new Array(BOSS_1_id, 5062002, 300, 1, 1), new Array(BOSS_1_id, 5062002, 300, 1, 1), new Array(BOSS_1_id, 1102481, 1, 1, 1), new Array(BOSS_1_id, 1102482, 1, 1, 1), new Array(BOSS_1_id, 1102483, 1, 1, 1), new Array(BOSS_1_id, 1102484, 1, 1, 1), new Array(BOSS_1_id, 1102485, 1, 1, 1), new Array(BOSS_1_id, 1082543, 1, 1, 1), new Array(BOSS_1_id, 1082544, 1, 1, 1), new Array(BOSS_1_id, 1082545, 1, 1, 1), new Array(BOSS_1_id, 1082546, 1, 1, 1), new Array(BOSS_1_id, 1082547, 1, 1, 1), new Array(BOSS_1_id, 1072743, 1, 1, 1), new Array(BOSS_1_id, 1072744, 1, 1, 1), new Array(BOSS_1_id, 1072745, 1, 1, 1), new Array(BOSS_1_id, 1072746, 1, 1, 1), new Array(BOSS_1_id, 1072747, 1, 1, 1), new Array(BOSS_1_id, 1132174, 1, 1, 1), new Array(BOSS_1_id, 1132175, 1, 1, 1), new Array(BOSS_1_id, 1132176, 1, 1, 1), new Array(BOSS_1_id, 1132177, 1, 1, 1), new Array(BOSS_1_id, 1132178, 1, 1, 1), new Array(BOSS_1_id, 4310143, 100, 1, 1), new Array(BOSS_1_id, 2049124, 22, 1, 1), new Array(BOSS_1_id, 2049137, 22, 1, 1), new Array(BOSS_1_id, 5150040, 8, 1, 1), new Array(BOSS_1_id, 5152053, 8, 1, 1));

function init() {}

function setup(g, b) {
    em.setProperty("state", "1");
    em.setProperty("leader", "true");
    var d = em.newInstance(副本名称);
    for (var c = 0; c < 实例地图.length; c++) {
        var f = d.setInstanceMap(实例地图[c]);
        f.resetPQ(g);
        f.resetFully();
        f.killAllMonsters(清怪);
        f.respawn(刷新地图)
    }
    d.startEventTimer(副本时限);
    d.setProperty("FBtime", 副本时限);
    d.setProperty("FBname", 副本名称);
    d.setProperty("strMap", 准备地图);
    var e = em.getMonster(BOSS_1_id).getMobMaxHp() * BOSS_1_血量倍率;
    d.setProperty("BOSShp", e);
    mobId = BOSS_1_id;
    mob = em.getMonster(mobId);
    mob.setOverrideStats();
    mob.getChangedStats().hp = e;
    mob.getChangedStats().mp = 99000000;
    mob.heal();
    d.registerMonster(mob);
    var a = d.getMapInstance(实例地图[1]);
    a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-430, 266));
    return d
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(0);
    a.dropMessage(6, "[" + 副本名称 + "] 进入到了挑战地图，请小心行事。");
    a.changeMap(c, c.getPortal(0));
    a.setReviveCount(复活次数);
    a.getAPI().setNumberForQuestInfo(准备地图, "damage", 0)
}

function onPlayerRevived(b, a) {
    if (a.getReviveCount() > 0) {
        return true
    } else {
        var c = b.getMapFactoryMap(准备地图);
        a.changeMap(c, c.getPortal(0));
        return true
    }
}

function onMapChanged(c, b, a) {
    if (实例地图.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    switch (a) {
        case 实例地图[0]:
            initProp("stage" + 1 + "_kill", 0);
            break;
        case 实例地图[1]:
            initProp("stage" + 1 + "_kill", 0);
            break
    }
}

function onMonsterKilled(b, c) {
    if (c == BOSS_1_id) {
        b.getPlayers().forEach(function (d) {
            d.getAPI().updateAchievement(3026, 0, 1, 1);
            d.getAPI().updateAchievement(3027, 0, 1, 10);
            d.getAPI().updateAchievement(3028, 0, 1, 100);
            d.getAPI().updateAchievement(3029, 0, 1, 100)
        });
        openNpc(b, 9130027, "评价系统");
        b.startEventTimer(退场倒计时 * 1000);
        for (var a = 0; a < b.getPlayerCount(); a++) {
            b.getPlayers().get(a).dropMessage(6, "[" + 副本名称 + "] 挑战成功！已召唤击杀奖励！！")
        }
    }
}

function onMonsterKilled(j, l, k) {
    var c = Math.floor(Math.random() * 33);
    var a = k.getId();
    var h = new Array();
    for (var g = 0; g < dropItems.length; g++) {
        if (a != dropItems[g][0]) {
            continue
        }
        var b = Math.floor(Math.random() * 10);
        if (b < dropItems[g][2]) {
            var f = dropItems[g][3];
            var e = dropItems[g][4];
            var d = Math.floor(Math.random() * (e - f + 1) + f);
            h.push(new Array(dropItems[g][1], d))
        }
    }
    for (var g = 0; g < h.length; g++) {
        if (l.getMap() != null) {
            j.getPlayers().forEach(function (o) {
                var n = cm.getNumberFromQuestInfo(准备地图, "damage");
                var m = ((n / j.getProperty("BOSShp")) * 100);
                if (m > 15) {
                    if (c > 31) {
                        o.getAPI().gainItem(h[g][0], h[g][1]);
                        j.setProperty("luck", "希纳斯的祝福：本次奖励为双倍！！！")
                    } else {
                        if (c > 29 && c <= 31) {
                            o.getAPI().gainMeso(奥尔卡的思念);
                            j.setProperty("luck", "奥尔卡的思念：本次每获得一件道具增加" + 奥尔卡的思念 + "金币！")
                        } else {
                            if (c > 27 && c <= 29) {
                                var i = [1712001, 1712002, 1712003, 1712004, 1712005, 1712006];
                                o.getAPI().gainItem(i[Math.floor(Math.random() * i.length)], 1);
                                j.setProperty("luck", "艾尔达之夙愿：本次每获得一件道具增加 神秘徽章 x1！")
                            } else {
                                if (c > 25 && c <= 27) {
                                    o.getAPI().getPlayer().modifyCSPoints(1, Math.floor(Math.random() * 希纳斯之吻));
                                    j.setProperty("luck", "希纳斯之吻：本次每获得一件道具增加随机点券！");
                                    o.dropMessage(5, "获得点券：" + Math.floor(Math.random() * 希纳斯之吻) + "")
                                } else {
                                    if (c > 23 && c <= 25) {
                                        o.getAPI().getPlayer().modifyCSPoints(1, -Math.floor(Math.random() * 路西德的噩梦));
                                        j.setProperty("luck", "路西德的噩梦：本次每获得一件道具减少随机点券！");
                                        o.dropMessage(5, "失去点券：" + Math.floor(Math.random() * 路西德的噩梦) + "")
                                    } else {
                                        if (c > 21 && c <= 23) {
                                            o.getAPI().gainMeso(-黑魔法师之怒);
                                            j.setProperty("luck", "黑魔法师之怒：本次每获得一件道具损失" + 黑魔法师之怒 + "金币！")
                                        } else {
                                            j.setProperty("luck", "什么都没发生,世界好像与你无关..")
                                        }
                                    }
                                }
                            }
                        }
                    }
                    o.getAPI().gainItem(h[g][0], h[g][1]);
                    var p = o.getAPI().getItemInfo();
                    o.dropMessage(-1, "获得道具：" + cm.getItemName(h[g][0]) + " x" + h[g][1] + "")
                }
            })
        }
    }
}

function onMonsterDamaged(b, a, d, e, c) {
    if (d == BOSS_1_id) {
        a.getAPI().addNumberForQuestInfo(准备地图, "damage", e)
    }
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function initPropArrayRandom(a, d, j, b, h) {
    var g = new Array();
    var k = h - b + 1;
    var c = (j - d) < (h - b) ? true : false;
    do {
        var f = randomNum(d, j);
        if (c || g.indexOf(f) < 0) {
            g.push(f);
            k--
        }
    } while (k);
    for (var e = b; e <= h; e++) {
        if (em.getProperty(a + "_" + e) == null) {
            em.setProperty(a + "_" + e, g[e - 1])
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onPlayerKilled(b, a) {}

function onPartyDisbanded(a) {
    on玩家退场(a, player, false)
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onItemPickedUp(b, a, c) {};